#pragma once

#include "rendernode.h"
#include "animation.h"


struct renderhierarchy_t
{
	stringhash name;
	vector<rendernode_t> node_buf;
	animationcontainer_t* animation;

	renderhierarchy_t* nextinhashmap;
	uint32 gethashkey(){return name.value;}
	void draw();
	void set_world_matrix();

#ifdef LEO_DESIGNER
	bool selected;
	void save();
#endif
	void load();


	renderhierarchy_t()
	{
		object_color.set(1,1,1,1);
		animation=0;
	}

	bool valid() const
	{
		return node_buf.size()>0;
	}

	rendernode_t* get_node(const stringhash& name)
	{
		for (unsigned n=1; n<node_buf.size(); ++n)
		{
			if (node_buf[n].name==name)
				return &node_buf[n];
		}

		return NULL;
	}

	void set_animation_frame(animation_t* anim0, const float anim0_time, animation_t* anim1=NULL, const float anim1_time=0, const float blend=0);


	color4f object_color;
};

	inl int get_nodeindex(const vector<rendernode_t>& node_buf, const stringhash& name)
	{
		for (unsigned n=1; n<node_buf.size(); ++n)
		{
			if (node_buf[n].name==name)
				return n;
		}

		return -1;
	}
